home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
H-K
/
Icon.sample.cpt
/
sieve.icn
< prev
next >
Wrap
Text File
|
1988-04-07
|
544b
|
20 lines
#
# S I E V E O F E R A T O S T H E N E S
#
# This program illustrates the use of sets in implementing the
# classical sieve algorithm for computing prime numbers.
procedure main(a)
local limit, s, i
limit := integer(a[1]) |100
s := set()
every insert(s,1 to limit)
every member(s,i := 2 to limit) do
every delete(s,i + i to limit by i)
primes := sort(s)
write("There are ",*primes," primes in the first ",limit," integers.")
write("The primes are:")
every write(right(!primes,*limit + 1))
end